import redis


class MyRedis:
    def __init__(self):
        self.r = redis.Redis(host='127.0.0.1', port=6379, db=1)

    # 字符串添加
    def set_str(self, key, value):
        self.r.set(key, value)

    # 设置时间字符串添加
    def set_time_str(self, key, value, time):
        self.r.setex(key, value, time)

    # 字符串添加
    def get_str(self, key):
        value = self.r.get(key)
        if value:
            return value.decode('utf-8')

    # 删除字符串
    def del_str(self, key):
        return self.r.delete(key)

    # 集合权重
    def set_score(self, key, vaule):
        return self.r.zincrby(key, 1, vaule)

    # 集合获取数据
    def get_set(self, key, len):
        return self.r.zrevrange(key, 0, len)

    def is_exist(self, key):
        return self.r.exists(key)

    def set_time(self, key, time):
        return self.r.expire(key, time)


# myredis = MyRedis()

